package com.baomibing.flow.model;

import com.baomibing.flow.constant.JoinExeTypeEnum;
import com.baomibing.flow.constant.NodeTypeEnum;
import com.baomibing.flow.execute.Execution;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * JoinNode
 *
 * @author frog 2023/9/25 14:37
 * @version 1.0.0
 **/
@Slf4j
@Data @Accessors(chain = true) @EqualsAndHashCode(callSuper = true)
@ToString
public class JoinNode extends WorkNode{

    private JoinExeTypeEnum exeType;

    public JoinNode(String name) {
        this.name = name;
        this.nodeType = NodeTypeEnum.Join.name();
    }

    //for json deserialize
    public JoinNode() {
        this.nodeType = NodeTypeEnum.Join.name();
    }

    @Override
    public void execute(Execution execution) {
        log.info("*****process: 正在执行JoinNode({}),执行人:{}", this.getName(), execution.getActor());
        List<TransitionNode> outputs = getOutputs();
        for (TransitionNode line : outputs) {
            line.execute(execution);
        }
    }

    @Override
    public void reject(Execution execution) {
        log.info("*****reject: 正在执行JoinNode reject 方法({}),执行人:{}", this.getName(), execution.getActor());
        for (TransitionNode line : getInputs()) {
            line.reject(execution);
        }
    }
}
